import React, { useState } from 'react'
import { Button, InputItem, NavBar, TextareaItem } from 'antd-mobile'
import HeaderSelector from '../../components/HeaderSelector'
import { update } from '../../api/index'
import { connect } from 'react-redux'

function LaoBanInfo(props) {
    const [param, setparam] = useState({})
    const [header, setheader] = useState(null)

    const handleChange = (type, value) => {
        setparam({ ...param, [type]: value })
    }

    const handleSave = () => {
        if(!header){
            return alert("please select header")
        }
        update({ ...param, header: header }).then((result) => {
            props.dispatch({type: "Update_User_Info",data: result})
        }).catch((err) => {
            alert(err)
            props.history.push("/login")
        });
    }

    return <div>
        <NavBar>老板信息页面</NavBar>
        <HeaderSelector setheader={setheader} />
        <InputItem onChange={v => handleChange("post", v)}>招聘职位：</InputItem>
        <InputItem onChange={v => handleChange("company", v)}>公司名称：</InputItem>
        <InputItem onChange={v => handleChange("salary", v)}>职位薪资：</InputItem>
        <TextareaItem title="职位要求: " rows={3} onChange={v => handleChange("info", v)}> </TextareaItem>
        <Button type="primary" onClick={handleSave}>保存</Button>
    </div>
}

export default connect()(LaoBanInfo)